/*     */ package com.newcrm.webapi.sub;
/*     */ 
/*     */ import com.newcrm.bean.User;
/*     */ import com.newcrm.db.TaskManager;
/*     */ import com.newcrm.exception.NotFoundException;
/*     */ import com.newcrm.util.Util;
/*     */ import com.newcrm.webapi.AbstractAction;
/*     */ import com.newcrm.webapi.AbstractHttpServlet;
/*     */ import java.io.IOException;
/*     */ import java.io.PrintWriter;
/*     */ import java.util.Date;
/*     */ import javax.servlet.ServletException;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import javax.servlet.http.HttpServletResponse;
/*     */ import net.sf.json.JSONObject;
/*     */ import org.apache.log4j.Logger;
/*     */ 
/*     */ public class UpdateTask extends AbstractAction
/*     */ {
/*  25 */   private static Logger logger = Logger.getLogger(UpdateTask.class.getName());
/*  26 */   private int id = 0;
/*     */ 
/*     */   public UpdateTask(AbstractHttpServlet servlet) {
/*  29 */     super(servlet);
/*     */   }
/*     */ 
/*     */   public UpdateTask(AbstractHttpServlet servlet, String id) {
/*  33 */     super(servlet);
/*  34 */     this.id = Util.str2Int(id);
/*     */   }
/*     */ 
/*     */   public void parse(HttpServletRequest request, HttpServletResponse response)
/*     */     throws IOException, ServletException, NotFoundException
/*     */   {
/*  40 */     String userId = super.getLoginUser(request).userId;
/*  41 */     TaskManager manager = new TaskManager();
/*  42 */     response.setContentType("text/html;charset=utf-8");
/*  43 */     PrintWriter out = response.getWriter();
/*  44 */     JSONObject jsonObject = new JSONObject();
/*     */ 
/*  46 */     if (this.id == 0) {
/*  47 */       this.id = Util.str2Int(request.getParameter("TaskId"));
/*     */     }
/*     */ 
/*  50 */     String updateType = Util.getURLParameter(request
/*  51 */       .getParameter("updateType"));
/*     */     try {
/*  53 */       if ("0".equals(updateType)) {
/*  54 */         int result = manager.updateStatus(this.id, 0, userId);
/*  55 */         jsonObject.put("error", "0");
/*  56 */         jsonObject.put("result", Integer.valueOf(result));
/*  57 */       } else if ("1".equals(updateType)) {
/*  58 */         int result = manager.updateStatus(this.id, 1, userId);
/*  59 */         jsonObject.put("error", "0");
/*  60 */         jsonObject.put("result", Integer.valueOf(result));
/*  61 */       } else if ("2".equals(updateType))
/*     */       {
/*  63 */         int dueDate = Util.str2Int(request.getParameter("DueDate"));
/*  64 */         int result = manager.updateDueDate(this.id, 
/*  65 */           Util.getDueDate(dueDate), userId);
/*  66 */         jsonObject.put("error", "0");
/*  67 */         jsonObject.put("result", Integer.valueOf(result));
/*     */       } else {
/*  69 */         String taskTitle = Util.getURLParameter(request
/*  70 */           .getParameter("TaskTitle"));
/*  71 */         String strDueDate = request.getParameter("DueDate");
/*     */ 
/*  75 */         int due = Util.str2Int(request.getParameter("Due"));
/*  76 */         Date dueDate = null;
/*     */ 
/*  78 */         if (due > 0)
/*     */         {
/*  80 */           dueDate = Util.getDueDate(due);
/*     */         }
/*  82 */         else if ((strDueDate != null) && (strDueDate.contains(":")))
/*  83 */           dueDate = Util.str2Date2(strDueDate);
/*     */         else {
/*  85 */           dueDate = Util.str2Date(strDueDate);
/*     */         }
/*     */ 
/*  89 */         String responsibleUserId = Util.getURLParameter(request
/*  90 */           .getParameter("ResponsibleUserId"));
/*  91 */         int categoryId = Util.getURLIntParameter(request
/*  92 */           .getParameter("CategoryId"));
/*  93 */         int taskVisible = Util.getURLIntParameter(request
/*  94 */           .getParameter("TaskVisible"));
/*  95 */         if (responsibleUserId == null) {
/*  96 */           responsibleUserId = userId;
/*     */         }
/*     */ 
/*  99 */         int result = manager.update(this.id, taskTitle, dueDate, 
/* 100 */           responsibleUserId, categoryId, taskVisible, userId);
/* 101 */         jsonObject.put("error", "0");
/* 102 */         jsonObject.put("result", Integer.valueOf(result));
/*     */       }
/*     */     } catch (Exception e) {
/* 105 */       logger.warn("update task status failed", e);
/* 106 */       jsonObject.put("error", "1");
/* 107 */       jsonObject.put("msg", "更新任务的过程中发现错误，请稍后再试");
/*     */     }
/* 109 */     out.println(jsonObject);
/* 110 */     out.flush();
/* 111 */     out.close();
/*     */   }
/*     */ }

/* Location:           C:\E\referenceProject\CRM参考\qikebao\WEB-INF\lib\qikebao.jar
 * Qualified Name:     com.newcrm.webapi.sub.UpdateTask
 * JD-Core Version:    0.6.1
 */